package com.hjl.config;

import com.hjl.interceptor.MyInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @author ServivE
 * @version 0.1
 * @className SpringMvcConfig
 * @description
 * @date 2024/8/13 16:36
 * @since jdk17
 */
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.hjl.controller","com.hjl.error"})
public class SpringMvcConfig implements WebMvcConfigurer {
    //配置jsp对应的视图解析器
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        //快速配置jsp模板语言对应的
        registry.jsp("/WEB-INF/views/",".jsp");
    }
    //开启静态资源处理 <mvc:default-servlet-handler/>
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
    //添加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //将拦截器添加到Springmvc环境,默认拦截所有Springmvc分发的请求
        registry.addInterceptor(new MyInterceptor());
    }
}
